<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<h1>
	<fmt:message key="accounts.edit.title" />
</h1>

<spring:url value="/accounts/{number}" var="accountUrl">
	<spring:param name="number" value="${account.number}" />
</spring:url>

<!--
 // Notice that error tags have been added to this form for you already.
 // They look like this:
 //      <form:errors cssClass="alert alert-danger" path="..." />
 --> 
<form:form modelAttribute="account" action="${accountUrl}" method="post" role="form" class="form-horizontal">
	<fieldset>
		<legend>
			<fmt:message key="accounts.edit.legend"/>
		</legend>
		<!--  Show the account number if there is one.
			  When creating a new account it will be empty.  -->
		<c:if test="${account.number != ''}">
			<div class="form-group">
				<label class="control-label col-sm-2" for="number">
					<fmt:message key="label.Account.number" />				
				</label>
				<div class="col-sm-4">
					<span class="form-control">${account.number}</span>
				</div>
				<div class="col-sm-6">
				</div>
			</div>
		</c:if>
		<div class="form-group">
			<label class="control-label col-sm-2" for="name">
				<fmt:message key="label.Account.name" />				
			</label>
			<div class="col-sm-4">
				<form:input path="name" class="form-control"/>
			</div>
			<div class="col-sm-6">
				<form:errors cssClass="alert alert-danger" path="name" />
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-2" for="dateOfBirth">
				<fmt:message key="label.Account.dateOfBirth" />
			</label>
			<div class="col-sm-4">
				<form:input path="dateOfBirth" class="form-control"/>
			</div>
			<div class="col-sm-6">
				<form:errors cssClass="alert alert-danger" path="dateOfBirth" />
			</div>
		</div>
		<div class="form-group">
			<label class="control-label col-sm-2" for="email">
				<fmt:message key="label.Account.email" />
			</label>
			<div class="col-sm-4">
				<form:input path="email" class="form-control"/>
			</div>
			<div class="col-sm-6">
				<form:errors cssClass="alert alert-danger" path="email" />
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2">
			</div>
			<div class="col-sm-4 checkbox">
				<label for="receiveNewsletter">
					<form:checkbox path="receiveNewsletter"/>
					<fmt:message key="label.Account.receiveNewsletter" />
				</label>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2">
			</div>
			<div class="col-sm-4 checkbox">
				<label for="receiveMonthlyEmailUpdate">
					<form:checkbox path="receiveMonthlyEmailUpdate"/>
					<fmt:message key="label.Account.receiveMonthlyEmailUpdate" />
				</label>
			</div>
		</div>
		<c:if test="${fn:length(account.beneficiaries) > 0}">
			<div class="container">
				<div class="col-sm-6">
					<table class="table">
						<thead>
							<tr>
								<th>
									<fmt:message key="label.Account.beneficiaries.name" />
								</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="beneficiary" items="${account.beneficiaries}">
								<tr>
									<td>${beneficiary.name}</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</c:if>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button id="saveButton" type="submit" class="btn button-default">
					<fmt:message key="command.save" />
				</button>		

				<a class="btn btn-info" href="${accountUrl}">
					<fmt:message key="command.cancel" />
				</a>
			</div>
		</div>
	</fieldset>
</form:form>